package com.ecube.maintenance.components.widget;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by wcx on 14-8-27.
 */
public class CircularImage extends ImageView {
    public CircularImage(Context context) {
        super(context);
    }

    public CircularImage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CircularImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @NonNull
    @Override
    protected void onDraw(Canvas canvas) {

        Path clipPath = new Path();
        int w = this.getWidth();
        int h = this.getHeight();
        float rad = ((float) Math.min(w, h)) / 2;
        /**
         * RectF  图片切圆
         * **/

        clipPath.addRoundRect(new RectF(0, 0, w, h),rad, rad,Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}
